package com.rdk.entity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

import com.rdk.utils.StringUtil;

public class ChatDataBean {

	// 姝ｉ潰鏁伴噺
	private Map<String, Integer> negativeNumMap = new HashMap<String, Integer>();

	// 璐熼潰鏁伴噺
	private Map<String, Integer> positiveNumMap = new HashMap<String, Integer>();

	// 中性
	private Map<String, Integer> normalNumMap = new HashMap<String, Integer>();

	private Map<String, Integer> totalNumMap = new HashMap<String, Integer>();
	
	private Map<String, Integer> emotionNumMap= new HashMap<String,Integer>();
	
	private Map<String, Double> emotionTmepMap = new HashMap<String, Double>();
	
	

	public Map<String, Double> getEmotionTmepMap() {
		return emotionTmepMap;
	}

	public void setEmotionTmepMap(Map<String, Double> emotionTmepMap) {
		this.emotionTmepMap = emotionTmepMap;
	}

	public Map<String, Integer> getEmotionNumMap() {
		return emotionNumMap;
	}

	public void setEmotionNumMap(Map<String, Integer> emotionNumMap) {
		this.emotionNumMap = emotionNumMap;
	}

	public Map<String, Integer> getTotalNumMap() {
		return totalNumMap;
	}

	public void setTotalNumMap(Map<String, Integer> totalNumMap) {
		this.totalNumMap = totalNumMap;
	}

	public Map<String, Integer> getNegativeNumMap() {
		return negativeNumMap;
	}

	public void setNegativeNumMap(Map<String, Integer> negativeNumMap) {
		this.negativeNumMap = negativeNumMap;
	}

	public Map<String, Integer> getPositiveNumMap() {
		return positiveNumMap;
	}

	public void setPositiveNumMap(Map<String, Integer> positiveNumMap) {
		this.positiveNumMap = positiveNumMap;
	}

	public Map<String, Integer> getNormalNumMap() {
		return normalNumMap;
	}

	public void setNormalNumMap(Map<String, Integer> normalNumMap) {
		this.normalNumMap = normalNumMap;
	}

	public ChatDataBean(String startTime, String endTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long startDayTime = 0;
		long endDayTime = 0;
		try {
			startDayTime = sdf.parse(startTime).getTime();
			endDayTime = sdf.parse(endTime).getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long day = 1000 * 60 * 60 * 24;
		long start = startDayTime;
		long end = endDayTime;
		long add = 0;
		if ((endDayTime - startDayTime) / day < 1) {
			add = 1000 * 60 * 60;
			sdf = new SimpleDateFormat("yyyyMMddHH");
		} else {
			add = day;
			sdf = new SimpleDateFormat("yyyyMMdd");
		}

		for (long i = start; i < end; i += add) {
			String t = sdf.format(new Date(i));
			negativeNumMap.put(t, 0);
			positiveNumMap.put(t, 0);
			normalNumMap.put(t, 0);
			emotionTmepMap.put(t, 0.0);
			totalNumMap.put(t, 0);
		}
	}

	public static void main(String[] args) {
		Map<String, Integer> ss = new HashMap<String, Integer>();
		ss.put("2016101209", 2016101209);
		ss.put("2016101219", 2016101219);
		ss.put("2016101202", 2016101202);
		ss.put("2016101200", 2016101200);
		ss.put("2016101003", 2016101003);
		ss.put("2016101109", 2016101109);
		System.out.println(transMapToString(ss));
	}

	public static List<Integer> transMapToString(Map oriMap) {
		java.util.Map.Entry entry;
		List<Integer> list = new ArrayList<Integer>();
		for (Iterator iterator = oriMap.entrySet().iterator(); iterator.hasNext();) {
			entry = (java.util.Map.Entry) iterator.next();
			list.add(null == entry.getValue() ? 0 : (Integer) entry.getValue());
		}
		return list;
	}

	public Map<String, Integer> sortMapByKey(Map<String, Integer> oriMap) {
		if (oriMap == null || oriMap.isEmpty()) {
			return null;
		}
		Map<String, Integer> sortedMap = new TreeMap<String, Integer>(new Comparator<String>() {
			public int compare(String key1, String key2) {
				int intKey1 = 0, intKey2 = 0;
				try {
					intKey1 = StringUtil.parseInt(key1);
					intKey2 = StringUtil.parseInt(key2);
				} catch (Exception e) {
					intKey1 = 0;
					intKey2 = 0;
				}
				return intKey1 - intKey2;
			}
		});
		sortedMap.putAll(oriMap);
		return sortedMap;
	}
	
	/**
	 * 处理情绪值，根据总量最大值，调整情绪值的比例。
	 * @param emMap
	 * @param maxTotal
	 * @return
	 */
	public Map<String, Integer> haldEmotion(Map<String, Double> emMap, int maxTotal ){
		
		Map<String, Integer> tempMap = new HashMap<String, Integer>();
		
		for(Entry<String, Double> entry : emMap.entrySet()){
			entry.getValue();
			double res = maxTotal/400.0*(entry.getValue()+200);
			if(res>Math.floor(res)){
				res += 1;
			}
			
			tempMap.put(entry.getKey(), (int)res);
		}
		
		return tempMap;
		
	}
}
